
// 茶叶添加加载图片
function tuPian() {
    let inplist =document.getElementsByTagName("input")
    let inpimg = inplist[1].files;
    let teaimgobj=inpimg[0];
    let teaimg=teaimgobj.name
    document.querySelector("img").src = "../img/" + teaimg;
}
// 茶叶添加的方法
function teaadd(){
    // id
    let teaid=1;
    let inplist =document.getElementsByTagName("input");
    //书名
    let teaname = inplist[0].value;
    let inpimg = inplist[1].files;
    let teaimgobj=inpimg[0];
    // 茶照片名
    let teaimg=teaimgobj.name
    // 类型
    let typelist=document.getElementsByTagName("option")
        for (i = 0; i < typelist.length; i++) {
        //判断哪个类型被选中
        if (typelist[i].selected == true) {
            var teatype = typelist[i].value
            break;
        }
    }
    // 价格
    let teaprice = inplist[2].value;
    let tea = {
        teaid:teaid,
        teaname:teaname,
        teaimg:teaimg,
        teatype:teatype,
        teaprice:teaprice
    }
    $.ajax({
        type: "post",
        url: "/js/teaadd",
        data: JSON.stringify(tea),
        dataType: "json",
        success: function (data) {
            if (data) {
                alert("添加成功")
            } else {
                alert("该茶已存在")
            }
        }
    })

    
}